﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Utilities;

namespace SM2TestRunner
{
    public class TestSuiteBuilder
    {
        public static TestSuite buildTestSuiteFromDataTable(DataTable dtSample)
        {   
            //Prepare data
            TestSuite tsItem = new TestSuite();

            //Read data from DataTable out, building testsuite
            int countRows = dtSample.Rows.Count;
            int i = 0;
            while (i < countRows)
            {
                //Get testcase
                TestCase tcItem = new TestCase();

                DataRow dr_run = dtSample.Rows[i++];
                string strCase = dr_run[0].ToString();
                string strDetail = dr_run[1].ToString();
                string[] listOfSteps = StringUtil.buildArrayElement(strDetail, "->", ",");

                for (int j = 0; j < listOfSteps.Length; j++)
                {
                    //Get testaction
                    TestStep taItem = new TestStep();

                    string strStep = listOfSteps[j];                    
                    taItem.setOwner(strStep);
                    taItem.setObjectName(strStep);
                    taItem.setAction(strStep);
                    //taItem.setParameters(strStep);
                    taItem.setValidation(strStep);

                    //Add teststep to testcase
                    tcItem.addTestStep(taItem);
                }

                //Add to testsuite
                tsItem.addTestCase(tcItem);
            }

            return tsItem;
        }
    }
}
